package novel.mzx.com.activity;

import android.support.design.widget.AppBarLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.callback.StringCallback;
import com.lzy.okgo.model.Response;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import novel.mzx.com.R;
import novel.mzx.com.adapter.MarkAdapter2;
import novel.mzx.com.base.BaseActivity;
import novel.mzx.com.bean.ScoreBean;
import novel.mzx.com.http.Api;
import novel.mzx.com.http.SpDataUtils;
import novel.mzx.com.utils.JSONUtils;
import novel.mzx.com.utils.SPUtils;
import novel.mzx.com.utils.ToastUtils;
import novel.mzx.com.utils.Util;

/**
 *  成绩查询界面
 * */

public class SearchActivity extends BaseActivity {

    @BindView(R.id.mIv)
    ImageView mIv;


    @BindView(R.id.app_bar)
    AppBarLayout app_bar;

    @BindView(R.id.iv_search)
    ImageView iv_search;

    @BindView(R.id.recyclerView)
    RecyclerView recyclerView;

    private LinearLayoutManager mLinearLayoutManager;


    @BindView(R.id.et_content)
    EditText et_content;

    @BindView(R.id.search)
    ImageView search;
    @BindView(R.id.tv_score)
    TextView tv_score;
    @BindView(R.id.tv_class)
    TextView tv_class;

    MarkAdapter2 adapter;
    @Override
    protected int getResourceId() {
        return R.layout.activity_search;
    }


    String update;


    @Override
    protected void initView() {
        super.initView();
        mLinearLayoutManager = new LinearLayoutManager(this, LinearLayout.VERTICAL,false);
        recyclerView.setLayoutManager(mLinearLayoutManager);


        String url = "https://p1.itc.cn/q_70/images01/20210916/fc70e7783bb24f568c32e28aa9ecaf69.png";
        Glide.with(this).load(url).into(mIv);

        getData();

    }





    @Override
    public void initData() {
        super.initData();
    }

    private void getData() {
        OkGo.<String>post(Api.mainHost+ Api.listscoreInfoUrl)
                .params("scoreUname", SpDataUtils.getUserName())
                .execute(new StringCallback() {
                    @Override
                    public void onSuccess(Response<String> response) {
                        Log.e("课程成绩",response.body());

                        ScoreBean codeBean = JSONUtils.parserObject(response.body(),ScoreBean.class);
                        int code = codeBean.getResultCode();
                        if(code == 200){

                            List<ScoreBean.Data> data = codeBean.getData();
                            if(data.size() > 0){
                                adapter = new MarkAdapter2(SearchActivity.this, R.layout.list_item_mark_search,data);
                                recyclerView.setAdapter(adapter);
                            }else {
                                ToastUtils.showToast(SearchActivity.this,"暂无该成绩!");
                            }
                        }
                    }

                    @Override
                    public void onError(Response<String> response) {
                        super.onError(response);

                    }
                });

    }


}
